package com.ctrip.study.algorithm.stack;

/**
 * 通过栈来实现单词的逆序.
 */
public class WordReserve {
	
	private static String reserve(String input) {
		MyArrayStack<Character> stack = new MyArrayStack<>(input.length());
		for (int i = 0; i < input.length(); i++) {
			Character c = input.charAt(i);
			stack.push(c);
		}
		String output = "";
		while(!stack.isEmpty()){
			output += stack.pop();
		}
		return output;
	}

	
	public static void main(String[] args) {
		String input = "world";
		String output = WordReserve.reserve(input);
		System.out.println(output);
	}

	
}
